{% extends "./inc/base.html" %}

{% block content %}
<section class="vbox">
    <header class="header bg-light dk">
        <div class="btn-group pull-right hide">
            <a href="/admin/category/add" class="btn btn-default btn-sm" type="button"><i class="fa fa-check-square-o"></i> 添加栏目</a>
        </div>
        <p>{{controller.meta_title}}</p>
    </header>
    <section class="scrollable wrapper">

        <section class="panel panel-default">
            <header class="panel-heading clearfix">
                <ul class="nav nav-tabs pull-left">
                    <li class="{{active|default('active', true)}}"><a  href="/admin/category/index"> 全部 </a></li>
                    <li class="{%if active==0%}active{%endif%}"><a  href="/admin/category/index/?mold=0">系统</a>
                    <li class="{%if active==1%}active{%endif%}"><a  href="/admin/category/index/?mold=1">独立</a>
                    <li class="{%if active==2%}active{%endif%}"><a  href="/admin/category/index/?mold=2">单页</a>
                    </li>
                </ul>
                <i title="" data-original-title="" class="fa fa-info-sign text-muted pull-right"  data-toggle="tooltip" data-placement="bottom" data-title=""><i class="fa fa-question-circle"></i></i>
            </header>
            <div class="row wrapper">

                <div class="col-sm-9 m-b-xs">
                    <div class="">
                        <div class="btn-group">
                            <a {%if ctx.param("mold")==null %} data-toggle="dropdown" {% endif %} class="btn btn-info btn-sm
                            {%if ctx.param('mold')==null %}dropdown-toggle{% endif %} " {%if ctx.param("mold") !='' %} href="/admin/category/add/?mold={{ctx.param('mold')}}"{%endif%}"
                                > 添加栏目 {%if ctx.param("mold")==null %}<span class="caret"></span>{% endif %}</a>
                            {%if ctx.param("mold")==null %}
                            <ul class="dropdown-menu">

                                <li> <a href="/admin/category/add/?mold=0"
                                        class="text-info">添加系统栏目</a></li>
                                <li> <a href="/admin/category/add/?mold=1"
                                        class="text-info">添加独立栏目</a></li>
                                <li> <a href="/admin/category/add/?mold=2"
                                        class="text-info">添加单页栏目</a></li>
                                <!--<li class="divider"></li>-->
                                <!--<li><a href="#">添加内容</a></li>-->
                            </ul>
                            {% endif %}
                        </div>

                        <a class="btn btn-sm btn-default ajax-post" target-form="sort" href="/{{ctx.controller}}/sort">
                            排序
                        </a>
                        <a class="btn btn-sm btn-default ajax-post" target-form="sort" href="/{{ctx.controller}}/puliccache">
                            更新栏目缓存
                        </a>
                        <div class="btn-group">
                        <a href="#" onclick="jQuery('#category').treetable('expandAll'); return false;" class="btn btn-sm btn-default ">
                            展开全部
                        </a>
                        <a  onclick="jQuery('#category').treetable('collapseAll'); return false;" href="#" class="btn btn-sm btn-default">
                            合并全部
                        </a>
                        </div>
                    </div>
                </div>

            </div>
            <div class="table-responsive">
                <table class="table table-hover b-t b-light treetable" id="category">
                    <thead>
                    <tr>
                        <th > 栏目名称 </th>
                        <th > 栏目ID </th>
                        <th style="width:80px;">排序</th>
                        <th class="">标识</th>
                        <th>栏目类型</th>
                        <th>绑定模型</th>
                        <th>访问</th>
                        <th class="">发布</th>
                        <th style="width:80px;">状态</th>
                        <th>移动端</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
      {%for val in list%}
<tr data-tt-id="{{val.id}}" {%if val.pid != 0 %} data-tt-parent-id="{{val.pid}}"{%else%}class="active" {%endif%}>
<td><span class='folder ui-draggable'>{{val.title}}</span> <a href="/admin/category/add/?pid={{val.id}}&mold={{val.mold}}" class="text-info"> <i class="glyphicon glyphicon-plus"></i></a> </td>
    <td>{{val.id}}</td>
<td><input class="form-control form-control-text sort" value="{{val.sort}}" name="sort" data-id="{{val.id}}"/></td>
<td>{{val.name}}</td>
<td> {%if val.mold == 0%}系统{%elif val.mold == 1%}独立{%elif val.mold==2%}单页{%endif%}</td>
<td> {%for m in val.model|strToArray%}
{{m|getmode('title')}}&nbsp;&nbsp;
{%endfor%}
</td>
<td><a class="text-info-dker" href="{{val.url}}" target="_blank"><i class="glyphicon glyphicon-link"></i></a></td>
<td>
{%if val.allow_publish == 0 %}封面{% elif val.allow_publish==1%}列表{%endif%}
</td>
<td> <a href="/admin/category/setstatus/?ids={{val.id}}&status={{1-val.status}}" class="active ajax-get" data-toggle="class">
<i class="fa fa-check text-success {%if val.status %}text-active{%else%}text{%endif%}"></i>
<i class="fa fa-times text-danger {%if val.status %}text{%else%}text-active{%endif%}"></i>
</a></td>
    <td><a href="/admin/category/isapp/?ids={{val.id}}&isapp={{1-val.isapp}}" class="active ajax-get" data-toggle="class">
        <i class="fa fa-check text-success {%if val.isapp %}text-active{%else%}text{%endif%}"></i>
        <i class="fa fa-times text-danger {%if val.isapp %}text{%else%}text-active{%endif%}"></i>
    </a></td>
<td><a class="text-info" href="/admin/category/edit/?cid={{val.id}}">编辑</a>
<a class="text-info delcate" href="javascript:void(0)" data-id="{{val.id}}">删除</a>
    {%if val.mold!=2%}
<a class="text-info" href="/admin/category/move/?from={{val.id}}">移动</a>
<a class="text-info" href="/admin/category/move/?merge=1&from={{val.id}}">合并</a></td>
    {%endif%}
</tr>
{%endfor%}


                    </tbody>
                </table>
            </div>
            <footer class="panel-footer">
                <div class="row">


                    <div class="col-sm-12 text-right text-center-xs">

                    </div>
                </div>
            </footer>
        </section>
    </section>

</section>

{% endblock %}

{% block script %}
<script src="/static/admin/js/treetable/jquery.treetable.js" type="text/javascript"></script>
<script type="text/javascript">
    $("#category").treetable({ expandable: true });
    jQuery('#category').treetable('expandAll')
  $(function () {
      $(".delcate").click(function () {
          var id = $(this).attr("data-id");
          swal({
              title: "确定删除?",
              text: "删除后不可恢复，请谨慎操作!",
              type: "warning",
              showCancelButton: true,
              confirmButtonColor: "#DD6B55",
              confirmButtonText: "确定!",
              cancelButtonText:"算了",
              closeOnConfirm: false }, function(){
              $.ajax({
                  url: "/admin/category/del/?confirm=1&id=" + id,
                  success: function (data) {
                      if(data.ok == 0){
                          swal({title:data.info, text:"", type:"success"},function () {
                              location.reload();
                          });

                      } else if(data.ok==1){
                          swal({
                              title: "确定删除?",
                              text: data.info+"删除后不可恢复，请谨慎操作!</br><code>您可以将该栏目内容移动到其它栏目，然后再删除</code></br><code>如果该栏目内容不需要保留，点击确定连同该栏目的内容一起删除！</code>",
                              html:true,
                              type: "warning",
                              showCancelButton: true,
                              confirmButtonColor: "#DD6B55",
                              confirmButtonText: "确定!",
                              cancelButtonText:"算了",
                              closeOnConfirm: false }, function(){
                              $.ajax({
                                  url: "/admin/category/del/?type=one&id=" + id,
                                  success: function (data) {
                                      if(data.ok == 0){
                                          swal({title:data.info, text:"", type:"success"},function () {
                                              location.reload();
                                          });

                                      } else{

                                      }
                                  }
                              });
                          })
                  }else if(data.ok==2) {
                          swal({
                              title: "确定删除?",
                              text: data.info+"删除后不可恢复，请谨慎操作!</br><code>您可以将该栏目的子栏目以及内容移动到其它栏目，然后再删除</code></br><code>如果该栏目(子栏目)下所有内容不需要保留，点击确定将一起删除！</code>",
                              html:true,
                              type: "warning",
                              showCancelButton: true,
                              confirmButtonColor: "#DD6B55",
                              confirmButtonText: "确定!",
                              cancelButtonText:"算了",
                              closeOnConfirm: false }, function(){
                              $.ajax({
                                  url: "/admin/category/del/?type=all&id=" + id,
                                  success: function (data) {
                                      if(data.ok == 0){
                                          swal({title:data.info, text:"", type:"success"},function () {
                                              location.reload();
                                          });

                                      } else{

                                      }
                                  }
                              });
                          })
                      }
              }
                  });
              })



      })
  })
</script>

{% endblock %}